package me.jessyan.mvparms.demo.mvp.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.jess.arms.base.BaseActivity;
import com.jess.arms.base.DefaultAdapter;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.platform.ai.control.R;



import butterknife.BindView;
import butterknife.OnClick;

import me.jessyan.mvparms.demo.di.component.DaggerUserComponent;
import me.jessyan.mvparms.demo.di.module.UserModule;
import me.jessyan.mvparms.demo.mvp.contract.UserContract;
import me.jessyan.mvparms.demo.mvp.model.entity.User;
import me.jessyan.mvparms.demo.mvp.presenter.UserPresenter;
import me.jessyan.mvparms.demo.mvp.ui.adapter.BaseFragmentPagerAdapter;
import me.jessyan.mvparms.demo.mvp.ui.fragment.RepertoryFragment;
import me.jessyan.mvparms.demo.util.AnimationUtil;

import static com.jess.arms.utils.Preconditions.checkNotNull;

// 注册界面
public class RepertoryActivity extends BaseActivity<UserPresenter> implements UserContract.View {
    @BindView(R.id.tab)
    TabLayout mTab;

    @BindView(R.id.vp)
    ViewPager mVp;

    private String[] mTitles = {"全部","库存","出库","异常"};
    private boolean[] inverts;
    private BaseFragmentPagerAdapter mPagerAdapter;
    @Override
    public void setupActivityComponent(AppComponent appComponent) {
        DaggerUserComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .userModule(new UserModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView(Bundle savedInstanceState) {
        return R.layout.activity_repertory; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        inverts = new boolean[mTitles.length];
        mVp.setOffscreenPageLimit(4);
        //设置mTab
        mPagerAdapter = new BaseFragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                switch (position) {
                    case 0://收益
                        return RepertoryFragment.newInstance("全部");
                    case 1://期限
                        return RepertoryFragment.newInstance("库存");
                    case 2://热度
                        return RepertoryFragment.newInstance("出库");
                    case 3://热度
                        return RepertoryFragment.newInstance("异常");
                    default:
                        return RepertoryFragment.newInstance("异常");
                }
            }

            @Override
            public int getCount() {
                return mTitles.length;
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return mTitles[position];
            }
        };
        mVp.setAdapter(mPagerAdapter);
        mTab.setupWithViewPager(mVp);
        AnimationUtil.setTabLayoutWithArrow(mTab,mVp,mTitles,inverts,mPagerAdapter);
    }


    @Override
    public void showLoading() {

    }



    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        //checkNotNull(message);
        //ArmsUtils.snackbarText(message);
        if (!message.isEmpty()) {
        }
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }


    @Override
    public void setAdapter(DefaultAdapter adapter) {

    }

    @Override
    public void loginReturn(User user) {

    }

    @Override
    public void logout() {

    }

    @Override
    public void uploadResult(String string) {

    }

    @OnClick(R.id.iv_back)
    public void onBack(View v){
        finish();
    }

}
